#!/usr/bin/env node

const http=require('http'),
      log=console.log;
http.createServer((req,res)=>{
  if(req.url!='/'){
    //提示404
    err(res);
    return;
  }

  log(`${req.method} ${req.url} HTTP/${req.httpVersion}`);
  log(req.headers);
  log('');

  if(req.method==='POST'){
    req.pipe(process.stdout);
    res.end('ok!');
  }else{
    //提示404
    err(res);
  }
}).listen(8080);

function err(res){
  let msg='Not Found!';

  res.statusCode=404;
  res.setHeader('Content-Length',msg.length);
  res.setHeader('Content-Type','text/plain');

  res.end(msg);
}
